﻿using IBLL;
using IDAL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.Diagnostics.CodeAnalysis;
using System.Security.AccessControl;

namespace WebAPIUI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class RoomController : ControllerBase
    {
        public RoomController(IRoomBll bll)
        {
            Bll = bll;
        }

        public IRoomBll Bll { get; }


        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        [HttpPost("AddRoom")]
        public async Task<int> AddRoom(Room room)
        {
            return await Bll.AddRoom(room);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("DelRoom")]
        public async Task<int> DelRoom(int id)
        {
            return await Bll.DelRoom(id);
        }

        /// <summary>
        /// 分页显示
        /// </summary>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [HttpGet("GetRoom")]
        public dynamic GetRoom(int index, int size)
        {
            return Bll.GetRoom(index, size);
        }


        //public IActionResult DaoChu()
        //{
        //    IWorkbook book=new XSSFWorkbook();
        //    var st = book.CreateSheet("房号表");

        //    var row=st.CreateRow(0);
        //    row.CreateCell(0).SetCellValue("编号");
        //    row.CreateCell(1).SetCellValue("名称");

        //    byte[] b;
        //    using (MemoryStream ms=new MemoryStream())
        //    {
        //        book.Write(ms);
        //        b = ms.ToArray();
        //    }
        //    return File(b, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "房号表.xlsx");
        //}

        //public IActionResult Imp(IFormFile file)
        //{
        //    using (MemoryStream ms = new MemoryStream())
        //    {
        //        file.CopyTo(ms);
        //        ms.Position = 0;
        //        IWorkbook book=new XSSFWorkbook();

        //        var sh = book.CreateSheet("房号表");
        //        int num=sh.LastRowNum;
        //        for (int i = 0; i < num; i++)
        //        {
        //            var row=sh.GetRow(i);
        //            var c1 = row.Cells[0];
        //        }
        //    }
        //    return Ok();
        //}


        //public IActionResult DaoRuRoom(IFormFile file)
        //{
        //    List<Room> rooms = new List<Room>();

        //    using (MemoryStream ms = new MemoryStream())
        //    {
        //        file.CopyTo(ms);
        //        ms.Position = 0;
        //        IWorkbook book = new XSSFWorkbook(ms);

        //        var sh = book.CreateSheet("房号表");
        //        int num=sh.LastRowNum;
        //        for (int i = 1; i < num; i++)
        //        {
        //            var row=sh.GetRow(i);

        //            Room room = new Room();
        //            room.Name = row.Cells[1].ToString();
        //            rooms.Add(room);
        //        }
        //    }

        //}
    }
}
